home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / flexcat / lib / c_c.sd < prev    next >
Text File  |  1999-04-19  |  5KB  |  232 lines

  1. ##stringtype C
  2. ##shortstrings
  3. /****************************************************************
  4.    This file was created automatically by `%fv'
  5.    from "%f0".
  6.  
  7.    Do NOT edit by hand!
  8. ****************************************************************/
  9.  
  10. /****************************************************************
  11.     This file uses the auto initialization possibilities of
  12.     Dice, gcc and SAS/C, respectively.
  13.  
  14.     Dice does this by using the keywords __autoinit and
  15.     __autoexit, SAS uses names beginning with _STI or
  16.     _STD, respectively. gcc uses the asm() instruction,
  17.     to emulate C++ constructors and destructors.
  18.  
  19.     Using this file you don't have *all* possibilities of
  20.     the locale.library. (No Locale or Language arguments are
  21.     supported when opening the catalog. However, these are
  22.     *very* rarely used, so this should be sufficient for most
  23.     applications.
  24. ****************************************************************/
  25.  
  26.  
  27. /*
  28.     Include files and compiler specific stuff
  29. */
  30. #include <exec/memory.h>
  31. #include <libraries/locale.h>
  32. #include <libraries/iffparse.h>
  33.  
  34. #include <proto/exec.h>
  35. #include <proto/dos.h>
  36. #include <proto/locale.h>
  37. #include <proto/utility.h>
  38. #include <proto/iffparse.h>
  39.  
  40. #include <stdlib.h>
  41. #include <string.h>
  42.  
  43.  
  44.  
  45. #include "%b_Cat.h"
  46.  
  47.  
  48. /*
  49.     Variables
  50. */
  51. struct FC_String %b_Strings[%n] = {
  52.     { (STRPTR) %s, %d }%(,)
  53. };
  54.  
  55. STATIC struct Catalog *%bCatalog = NULL;
  56. #ifdef LOCALIZE_V20
  57. STATIC STRPTR %bStrings = NULL;
  58. STATIC ULONG %bStringsSize;
  59. #endif
  60.  
  61.  
  62. #if defined(_DCC)
  63. STATIC __autoexit VOID _STDClose%bCatalog(VOID)
  64. #elif defined(__SASC)
  65. VOID _STDClose%bCatalog(VOID)
  66. #elif defined(__GNUC__)
  67. STATIC VOID _STDClose%bCatalog(VOID)
  68. #else
  69. VOID Close%bCatalog(VOID)
  70. #endif
  71.  
  72. {
  73.     if (%bCatalog) {
  74.     CloseCatalog(%bCatalog);
  75.     }
  76. #ifdef LOCALIZE_V20
  77.     if (%bStrings) {
  78.     FreeMem(%bStrings, %bStringsSize);
  79.     }
  80. #endif
  81. }
  82.  
  83.  
  84. #if defined(_DCC)
  85. STATIC __autoinit VOID _STIOpen%bCatalog(VOID)
  86. #elif defined(__SASC)
  87. VOID _STIOpen%bCatalog(VOID)
  88. #elif defined(__GNUC__)
  89. VOID _STIOpen%bCatalog(VOID)
  90. #else
  91. VOID Open%bCatalog(VOID)
  92. #endif
  93.  
  94. {
  95.     if (LocaleBase) {
  96.     if ((%bCatalog = OpenCatalog(NULL, (STRPTR) "%b.catalog",
  97.                      OC_BuiltInLanguage, %l,
  98.                      OC_Version, %v,
  99.                      TAG_DONE))) {
  100.         struct FC_String *fc;
  101.         int i;
  102.  
  103.         for (i = 0, fc = %b_Strings;  i < %n;  i++, fc++) {
  104.          fc->msg = GetCatalogStr(%bCatalog, fc->id, (STRPTR) fc->msg);
  105.         }
  106.     }
  107.     }
  108. }
  109.  
  110. #if defined(__GNUC__)
  111. __asm ("  .text;  .stabs \\\"___CTOR_LIST__\\\",22,0,0,__STIOpen%bCatalog");
  112. __asm ("  .text;  .stabs \\\"___DTOR_LIST__\\\",22,0,0,__STDClose%bCatalog");
  113. #endif
  114.  
  115.  
  116.  
  117. #ifdef LOCALIZE_V20
  118. VOID Init%bCatalog(STRPTR language)
  119.  
  120. {
  121.     struct IFFHandle *iffHandle;
  122.  
  123.     /*
  124.     **  Use iffparse.library only, if we need to.
  125.     */
  126.     if (LocaleBase  ||  !IFFParseBase  ||  !language  ||
  127.     Stricmp(language, %l) == 0) {
  128.     return;
  129.     }
  130.  
  131.     if ((iffHandle = AllocIFF())) {
  132.     char path[128]; /* Enough to hold 4 path items (dos.library 3.1)    */
  133.     strcpy(path, "PROGDIR:Catalogs");
  134.     AddPart((STRPTR) path, language, sizeof(path));
  135.     AddPart((STRPTR) path, "%b.catalog", sizeof(path));
  136.     if (!(iffHandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))) {
  137.         strcpy(path, "LOCALE:Catalogs");
  138.         AddPart((STRPTR) path, language, sizeof(path));
  139.         AddPart((STRPTR) path, language, sizeof(path));
  140.         iffHandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
  141.     }
  142.  
  143.     if (iffHandle->iff_Stream) {
  144.         InitIFFasDOS(iffHandle);
  145.         if (!OpenIFF(iffHandle, IFFF_READ)) {
  146.         if (!PropChunk(iffHandle, MAKE_ID('C','T','L','G'),
  147.                    MAKE_ID('S','T','R','S'))) {
  148.             struct StoredProperty *sp;
  149.             int error;
  150.  
  151.             for (;;) {
  152.             if ((error = ParseIFF(iffHandle, IFFPARSE_STEP))
  153.                    ==  IFFERR_EOC) {
  154.                 continue;
  155.             }
  156.             if (error) {
  157.                 break;
  158.             }
  159.  
  160.             if ((sp = FindProp(iffHandle, MAKE_ID('C','T','L','G'),
  161.                        MAKE_ID('S','T','R','S')))) {
  162.                 /*
  163.                 **  Check catalog and calculate the needed
  164.                 **  number of bytes.
  165.                 **  A catalog string consists of
  166.                 **      ID (LONG)
  167.                 **      Size (LONG)
  168.                 **      Bytes (long word padded)
  169.                 */
  170.                 LONG bytesRemaining;
  171.                 LONG *ptr;
  172.  
  173.                 %bStringsSize = 0;
  174.                 bytesRemaining = sp->sp_Size;
  175.                 ptr = (LONG *) sp->sp_Data;
  176.  
  177.                 while (bytesRemaining > 0) {
  178.                 LONG skipSize, stringSize;
  179.  
  180.                 ptr++;                  /*  Skip ID     */
  181.                 stringSize = *ptr++;
  182.                 skipSize = ((stringSize+3) >> 2);
  183.  
  184.                 %bStringsSize += stringSize+1;  /*  NUL */
  185.                 bytesRemaining -= 8 + (skipSize << 2);
  186.                 ptr += skipSize;
  187.                 }
  188.  
  189.                 if (!bytesRemaining  &&
  190.                 (%bStrings = AllocMem(%bStringsSize, MEMF_ANY))) {
  191.                 STRPTR sptr;
  192.  
  193.                 bytesRemaining = sp->sp_Size;
  194.                 ptr = (LONG *) sp->sp_Data;
  195.                 sptr = %bStrings;
  196.  
  197.                 while (bytesRemaining) {
  198.                     LONG skipSize, stringSize, id;
  199.                     struct FC_String *fc;
  200.                     int i;
  201.  
  202.                     id = *ptr++;
  203.                     stringSize = *ptr++;
  204.                     skipSize = ((stringSize+3) >> 2);
  205.  
  206.                     CopyMem(ptr, sptr, stringSize);
  207.                     bytesRemaining -= 8 + (skipSize << 2);
  208.                     ptr += skipSize;
  209.  
  210.                     for (i = 0, fc = %b_Strings;  i < %n;  i++, fc++) {
  211.                     if (fc->id == id) {
  212.                         fc->msg = sptr;
  213.                     }
  214.                     }
  215.  
  216.                     sptr += stringSize;
  217.                     *sptr++ = '\\0';
  218.                 }
  219.                 }
  220.                 break;
  221.             }
  222.             }
  223.         }
  224.         CloseIFF(iffHandle);
  225.         }
  226.         Close(iffHandle->iff_Stream);
  227.     }
  228.     FreeIFF(iffHandle);
  229.     }
  230. }
  231. #endif
  232.